package com.activity.shop;

import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.activity.bean.AttanceRecordBean;
import com.activity.bean.CheckBean;
import com.example.apple.ddhr_new.R;
import com.example.apple.ddhr_new.utils.ScreenUtil;
import com.example.lzbase.BaseViewModelActivity;
import com.google.gson.Gson;

import java.text.SimpleDateFormat;
import java.util.Date;

import androidx.annotation.Nullable;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ClockDetailActivity extends BaseViewModelActivity {


    @BindView(R.id.tv_date)
    TextView tvDate;
    @BindView(R.id.l_class)
    LinearLayout lclass;
    @BindView(R.id.tv_name)
    TextView tvName;
    @BindView(R.id.tv_class)
    TextView tvClass;

    @BindView(R.id.tv_addre)
    TextView tv_addre;
    @BindView(R.id.dot_top)
    View dotTop;
    @BindView(R.id.line_start)
    View lineStart;
    @BindView(R.id.line_end)
    View line_end;
    @BindView(R.id.tv_member)
    TextView tv_member;
    @BindView(R.id.tv_time)
    TextView tvTime;
    @BindView(R.id.tv_que_ka)
    TextView tvQueKa;
    @BindView(R.id.clock_time_start)
    TextView clockTimeStart;
    @BindView(R.id.tv_address_start)
    TextView tvAddressStart;
    @BindView(R.id.r_start)
    RelativeLayout rStart;
    @BindView(R.id.dot_bottom)
    View dotBottom;
    @BindView(R.id.tv_end_time)
    TextView tvEndTime;
    @BindView(R.id.tv_que_ka_end)
    TextView tvQueKaEnd;
    @BindView(R.id.clock_time)
    TextView clockTime;
    @BindView(R.id.tv_address)
    TextView tvAddress;
    @BindView(R.id.r_end)
    RelativeLayout rEnd;
    @BindView(R.id.l_bottom)
    LinearLayout lBottom;
    private AttanceRecordBean recordBean;

    @Override
    protected int titleText() {
        return R.string.daka_jilu_xiangqin;
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_clock_detail;
    }

    @Override
    protected void created(@Nullable Bundle savedInstanceState) {
        super.created(savedInstanceState);


        Gson gson = new Gson();

        recordBean = gson.fromJson(getIntent().getExtras().getString("param"), AttanceRecordBean.class);

        tvDate.setText(recordBean.getCheckinaddtime());

        tvName.setText("考勤组:" + recordBean.getCheckinattendancegroupname());

        tvClass.setText("班次:" + recordBean.getCheckinattendacetimespanname() + " " + recordBean.getCheckinattendacetimespan_begintime() + "-" + recordBean.getCheckinattendacetimespan_endtime() + " " + recordBean.getHours());

        tv_addre.setText("位置:" + recordBean.getCheckinlocation());
        tv_member.setText(recordBean.getUserinfo().get(0).getUsernickname());

        resetData();

    }

    public void resetData() {
        AttanceRecordBean today = recordBean;
        tvTime.setText("上班时间" + " " + today.getCheckinattendacetimespan_begintime());
        tvEndTime.setText("下班时间" + " " + today.getCheckinattendacetimespan_endtime());
        if (today.getStart() == null) {

            clockTimeStart.setVisibility(View.GONE);
            tvAddressStart.setVisibility(View.INVISIBLE);

            tvQueKa.setVisibility(View.VISIBLE);


            if (today.getEnd() == null) {

                clockTime.setVisibility(View.GONE);
                tvAddress.setVisibility(View.GONE);
                tvQueKaEnd.setVisibility(View.VISIBLE);



            } else {


                clockTime.setVisibility(View.VISIBLE);
                tvAddress.setVisibility(View.VISIBLE);
                tvQueKaEnd.setVisibility(View.GONE);

                clockTime.setText("打卡时间" + " " + today.getEnd().getCheckinrecordactualtime());
                tvEndTime.setText("下班时间"+" "+today.getCheckinattendacetimespan_endtime());
                tvAddress.setText(today.getEnd().getCheckinrecordlocation());

                Drawable mTipsIcon = null;
                if(today.getEnd().getCheckinrecordstatus().equals("-1")){
                    mTipsIcon = getResources().getDrawable(R.drawable.yichangdaka);
                }else {
                    mTipsIcon = getResources().getDrawable(R.drawable.icon_anotation);
                }


                mTipsIcon.setBounds(0, 0, (int) (mTipsIcon.getMinimumWidth() ),
                        (int) (mTipsIcon.getMinimumHeight() ));
                tvAddress.setCompoundDrawablePadding(ScreenUtil.dp2px(this,5));

                tvAddress.setCompoundDrawables(mTipsIcon,null,null,null);

            }


        } else {
            clockTimeStart.setVisibility(View.VISIBLE);
            tvAddressStart.setVisibility(View.VISIBLE);


            tvQueKa.setVisibility(View.GONE);
            tvTime.setText("上班时间"+" "+today.getCheckinattendacetimespan_begintime());
            clockTimeStart.setText("打卡时间" + " " + today.getStart().getCheckinrecordactualtime());
            tvAddressStart.setText(today.getStart().getCheckinrecordlocation());

            Drawable mTipsIcon = null;
            if(today.getStart().getCheckinrecordstatus().equals("-1")){
                mTipsIcon = getResources().getDrawable(R.drawable.yichangdaka);
            }else {
                mTipsIcon = getResources().getDrawable(R.drawable.icon_anotation);
            }


            mTipsIcon.setBounds(0, 0, (int) (mTipsIcon.getMinimumWidth() ),
                    (int) (mTipsIcon.getMinimumHeight() ));
            tvAddressStart.setCompoundDrawablePadding(ScreenUtil.dp2px(this,5));

            tvAddressStart.setCompoundDrawables(mTipsIcon,null,null,null);

            if (today.getEnd() == null) {

                clockTime.setVisibility(View.GONE);
                tvAddress.setVisibility(View.GONE);
                tvQueKaEnd.setVisibility(View.VISIBLE);



            } else {


                clockTime.setVisibility(View.VISIBLE);
                tvAddress.setVisibility(View.VISIBLE);
                tvQueKaEnd.setVisibility(View.GONE);
                clockTime.setText("打卡时间" + " " + today.getEnd().getCheckinrecordactualtime());
                tvEndTime.setText("下班时间"+" "+today.getCheckinattendacetimespan_endtime());
                tvAddress.setText(today.getEnd().getCheckinrecordlocation());
                Drawable mTipsIcon1 = null;
                if(today.getEnd().getCheckinrecordstatus().equals("-1")){
                    mTipsIcon1 = getResources().getDrawable(R.drawable.yichangdaka);
                }else {
                    mTipsIcon1 = getResources().getDrawable(R.drawable.icon_anotation);
                }


                mTipsIcon1.setBounds(0, 0, (int) (mTipsIcon1.getMinimumWidth() ),
                        (int) (mTipsIcon1.getMinimumHeight() ));
                tvAddress.setCompoundDrawablePadding(ScreenUtil.dp2px(this,5));

                tvAddress.setCompoundDrawables(mTipsIcon1,null,null,null);
            }

        }


        if(today.getOverTimeCheck().size()>0){

            for(int i=0;i<today.getOverTimeCheck().size();i++){

                CheckBean checkBean = today.getOverTimeCheck().get(i);
                View view = View.inflate(this, R.layout.layout_jiaban, null);
                View dot_bottom =view.findViewById(R.id.dot_bottom);
                TextView tv_end_time =view.findViewById(R.id.tv_end_time);
                TextView clock_time =view.findViewById(R.id.clock_time);
                TextView tv_address =view.findViewById(R.id.tv_address);
                View line_start =view.findViewById(R.id.line_start);
//                clock_time.setText("打卡时间" + " " + checkBean.getCheckinrecordactualtime());
//                tv_end_time.setText("下班时间" + " " + today.getCheckinattendacetimespan_endtime());

                if(checkBean.getCheckinrecordkind().equals("1")){
                    clock_time.setText("打卡时间" + " " + checkBean.getCheckinrecordactualtime());
                    tv_end_time.setText("下班时间" + " " + today.getCheckinattendacetimespan_endtime());

                }else {
                    if(checkBean.getCheckinrecordcategory().equals("1")){
                        clock_time.setText("外出时间" + " " + checkBean.getCheckinrecordactualtime());
                        tv_end_time.setText("下班时间" + " " + today.getCheckinattendacetimespan_endtime());

                    }else {
                        clock_time.setText("外出结束时间" + " " + checkBean.getCheckinrecordactualtime());
                        tv_end_time.setText("下班时间" + " " + today.getCheckinattendacetimespan_endtime());

                    }
                }
                tv_address.setText(checkBean.getCheckinrecordlocation());

                Drawable mTipsIcon = null;
                if(checkBean.getCheckinrecordstatus().equals("-1")){
                    mTipsIcon = getResources().getDrawable(R.drawable.yichangdaka);
                }else {
                    mTipsIcon = getResources().getDrawable(R.drawable.icon_anotation);
                }


                mTipsIcon.setBounds(0, 0, (int) (mTipsIcon.getMinimumWidth() ),
                        (int) (mTipsIcon.getMinimumHeight() ));
                tv_address.setCompoundDrawablePadding(ScreenUtil.dp2px(this,5));

                tv_address.setCompoundDrawables(mTipsIcon,null,null,null);

                if(today.getOverTimeCheck().size()==(i+1)){
                    line_start.setVisibility(View.GONE);
                }else {


                }
                lclass.addView(view);
            }
            line_end.setVisibility(View.VISIBLE);
        }else {
            line_end.setVisibility(View.GONE);
        }


    }



    @OnClick({R.id.tv_que_ka, R.id.tv_que_ka_end})
    public void onViewClicked(View view) {
        switch (view.getId()) {
            case R.id.tv_que_ka:
                break;
            case R.id.tv_que_ka_end:
                break;
        }
    }
}
